package org.enwey.icarenew.Component;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.enwey.icarenew.Model.New;
import org.enwey.icarenew.R;


/**
 * Created by enwey on 2014/11/20.
 */
public class NewItem extends LinearLayout {
    private TextView mExhibitor;
    private TextView mNewTitle;
    private TextView mNewDate;
    private TextView mSupportNum;
    private TextView mCommentNum;

    public NewItem(Context context) {
        super(context);
        initView();
    }

    public NewItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    private void initView() {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.new_item, this);
        findView(view);
    }

    private void findView(View view) {
        mNewTitle = (TextView) view.findViewById(R.id.new_item_title);
        mNewDate = (TextView) view.findViewById(R.id.new_item_date);
        mExhibitor = (TextView) view.findViewById(R.id.new_item_exhibitor);
        mSupportNum = (TextView) view.findViewById(R.id.new_item_support);
        mCommentNum = (TextView) view.findViewById(R.id.new_item_comment);
    }

    public void setNewData(New mNew) {
        mNewTitle.setText(mNew.title + "");
        mNewDate.setText(mNew.date + "");
        mExhibitor.setText(mNew.exhibitor + "");
        if (mNew.support.length() > 3) {
            mSupportNum.setText("999+");
        } else {
            mSupportNum.setText(mNew.support + "");
        }

        if (mNew.comment.length() > 3) {
            mCommentNum.setText("999+");
        } else {
            mCommentNum.setText(mNew.comment + "");
        }
    }
}
